package com.shenzhen.horselive.common.utils;

import android.util.Log;
import android.widget.ImageView;


import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

public class GlideHelpers {

//    /**
//     * 绑定Adapter的ImageView
//     *
//     * @param imageView
//     * @param url       图片地址
//     */
//    public static void loadImage(ImageView imageView, Object url) {
//        Log.d("kami", "url:" + url);
//        Glide.with(imageView.getContext()).load(url)
//                .placeholder(R.drawable.game_logo) //加载成功前显示的图片
//                .error(R.drawable.game_logo) //异常时候显示的图片
//                .fallback(R.drawable.game_logo) //url为空的时候,显示的图片
//                .into(imageView);
//    }

    /**
     * 绑定Adapter的ImageView
     *
     * @param imageView
     * @param url       图片地址
     */
    public static void loadImage(ImageView imageView, Object url) {
        Log.d("kami", "url:" + url);
        Glide.with(imageView.getContext()).load(url)
                .into(imageView);
    }


    public static void loadAdvertImage(@NonNull String photoUrl, @NonNull ImageView image) {
        Glide.with(image.getContext()).load(photoUrl)
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(image);
    }


    /**
     * 加载有圆角的头像
     *
     *
     * @param imageView
     * @param url       图片地址
     */
    public static void loadavaterImage(ImageView imageView, Object url) {
        RoundedCorners roundedCorners = new RoundedCorners(10);
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        Glide.with(imageView.getContext()).load(url)
                .apply(options)
                .into(imageView);
    }

}
